/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VerKardex.java
 *
 * Created on 21/03/2012, 04:23:38 PM
 */
package com.torresquintero.oncologos.quimioterapia.vista;

import com.torresquintero.oncologos.common.vista.OncologosTableModel;
import com.torresquintero.oncologos.common.vista.PanelOncologos;
import com.torresquintero.oncologos.entidades.Articulo;
import com.torresquintero.oncologos.secretaria.controladores.KardexController;
import java.util.List;

/**
 *
 * @author diana
 */
public class PanelVerKardex extends PanelOncologos {

    private KardexController control;
    /** Creates new form VerKardex */
    public PanelVerKardex() {
        initComponents();
        control=KardexController.getInstance();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTxNomArticulo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTxCodigo = new javax.swing.JTextField();
        jBBuscar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaInventario = new javax.swing.JTable();

        jLabel1.setText("Nombre:");

        jTxNomArticulo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxNomArticuloKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTxNomArticuloKeyTyped(evt);
            }
        });

        jLabel2.setText("Codigo");

        jBBuscar.setText("Buscar");
        jBBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBBuscarActionPerformed(evt);
            }
        });

        tablaInventario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Codigo", "Nombre", "Cantidad"
            }
        ));
        jScrollPane1.setViewportView(tablaInventario);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jTxCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jBBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTxNomArticulo, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBBuscar)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxNomArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(30, 30, 30)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTxNomArticuloKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxNomArticuloKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTxNomArticuloKeyTyped

    private void jBBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBBuscarActionPerformed
        // TODO add your handling code here:
        llenarTabla();
    }//GEN-LAST:event_jBBuscarActionPerformed

    private void jTxNomArticuloKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxNomArticuloKeyReleased
        // TODO add your handling code here:
        llenarTabla();
    }//GEN-LAST:event_jTxNomArticuloKeyReleased
    
     public void llenarTabla() {
        List<Articulo> lista = control.listarArticulos(jTxNomArticulo.getText(), jTxCodigo.getText());
        String titulos = "Codigo,Nombre,Cantidad";

        String campos = "codigo,nombre,cantidad";

        OncologosTableModel tabla = new OncologosTableModel(lista, campos, titulos);
        tablaInventario.setModel(tabla);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBBuscar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTxCodigo;
    private javax.swing.JTextField jTxNomArticulo;
    private javax.swing.JTable tablaInventario;
    // End of variables declaration//GEN-END:variables
}
